import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig } from 'vite';
import compressPlugin from 'vite-plugin-compression';
import base from './base.js';

export const DEFINE = {
  ___ENTRY___: 'src/main.jsx',
};

export default defineConfig(async ({ command, mode, ssrBuild }) => {
  let o = {
    mode: mode,
    define: {
      ...DEFINE,
    },
    plugins: [
      compressPlugin({
        ext: '.gz',
      }),
      visualizer({
        filename: './node_modules/.cache/visualizer/stats.html',
        open: false,
        gzipSize: true,
        brotliSize: true,
      }),
    ].filter(Boolean),
    build: {
      outDir: 'dist/doc',
      emptyOutDir: true,
      cssCodeSplit: true,
      assetsInlineLimit: 0,
    },
  };

  return await base({ command, mode, ssrBuild }, o);
});
